package mygang.service.manager;

import java.util.ArrayList;
import java.util.List;
import mygang.dao.manager.TableDAO;
import mygang.model.ColumnModel;
import mygang.model.TableModel;
import mygang.model.constructor.TableWizardModel;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

/**
 *
 * @author Volodymyr Lavrynovych <volodya.lavrynovych@gmail.com>
 * date: 23/02/2013
 */
@Service("tableService")
public class TableServiceImpl <D extends TableDAO> extends AbstractManageService<D, TableWizardModel> implements TableService{

    private static final Logger log = Logger.getLogger(TableServiceImpl.class.toString());

    public List<TableModel> getTableList() {
        return getDao().getTableList();
    }

    public List<ColumnModel> getTableColumns(String tableName) {
        return getDao().getTableColumns(tableName);
    }

    public TableModel getTableByName(String tableName) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void delete(TableWizardModel table) {
        getDao().delete(table);
    }

    public String getTablePrimaryColumn(String tableName) {
        return getDao().getTablePrimaryColumn(tableName);
    }

    public List<TableModel> getUniqueList() {
        List<TableWizardModel> tables = getDao().getAll();
        List<TableModel> fullList = getDao().getTableList();
        List<TableModel> usedList = new ArrayList<TableModel>();
        
        for(TableWizardModel table : tables){
            usedList.add(new TableModel(table.getName()));
        }
        fullList.removeAll(usedList);
        return fullList;
    }

    public String getColumnType(String table, String column) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}